using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using GraphAlgsPresentation.Core;

namespace GraphAlgsPresentation.ScriptLibrary
{
    /// <summary>
    /// Provides a change edge style command
    /// </summary>
    [Serializable]
    public class ChangeEdgeStyle:Command
    {
        private DashStyle newStyle;
        private DashStyle oldStyle;
        
        private string srcName, dstName;

        #region Properties
        /// <summary>
        /// returns source vertex's name
        /// </summary>
        public string SourceName
        {
            get { return srcName; }
            set { srcName = value; }
        }

        /// <summary>
        /// returns destination vertex's name
        /// </summary>
        public string DestinationName
        {
            get { return dstName; }
            set { dstName = value; }
        }

        /// <summary>
        /// return new edge's style
        /// </summary>
        public DashStyle NewStyle
        {
            get { return newStyle; }
            set { newStyle = value; }
        }
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeEdgeStyle"/> class.
        /// </summary>
        /// <param name="v1">Source vertex's id</param>
        /// <param name="v2">Destination vertex's id</param>
        /// <param name="style">The style.</param>
        /// <param name="effect">The effect.</param>
        public ChangeEdgeStyle(string v1, string v2, DashStyle style, DrawEffect effect)
        {
            srcName = v1;
            dstName = v2;
            newStyle = style;
            Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeEdgeStyle"/> class.
        /// </summary>
        /// <param name="v1">Source vertex's id</param>
        /// <param name="v2">Destination vertex's id</param>
        /// <param name="style">The style.</param>
        /// <param name="effect">The effect.</param>
        public ChangeEdgeStyle(int v1, int v2, DashStyle style, DrawEffect effect)
        {
            this.srcName = (v1 + 1).ToString();
            this.dstName = (v2 + 1).ToString();
            this.newStyle = style;
            this.Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeEdgeStyle"/> class.
        /// </summary>
        public ChangeEdgeStyle()
        {
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        public override void Run()
        {
            LCEdge e = this.Context.GetEdge(srcName, dstName);
            oldStyle = e.Style;
            e.Style = newStyle;
            e.Updated = true;
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            LCEdge e = this.Context.GetEdge(srcName, dstName);
            e.Style = oldStyle;
            e.Updated = true;
        }
    }
}
